﻿@model VideoCache.Server.MVCWeb.Areas.Admin.Models.AlbumModel
@{
    ViewBag.Title = "修改视频";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
@section script
{
    <script type="text/javascript">
        var searchResult;
        function selectItem(index) {
            if (searchResult.length > index) {
                $("#Title").val(searchResult[index].Title);
                $("#TypeId").val(searchResult[index].TypeId);
                $("#AreaId").val(searchResult[index].AreaId);
                $("#Rating").val(searchResult[index].Rating);
                $("#Directors").val(searchResult[index].Directors);
                $("#Actors").val(searchResult[index].Actors);
                $("#PubYear").val(searchResult[index].PubYear);
                if (searchResult[index].TypeId == 2) {
                    $("#IsEnd").attr("checked", true);
                }
                else {
                    $("#IsEnd").attr("checked", searchResult[index].IsEnd);
                }
                $("#Priority").val(searchResult[index].Priority);
                //$("#Status").val(searchResult[index].Status);
                $("#Description").val(searchResult[index].Description);
                $("#BaiduId").val(searchResult[index].BaiduId);
            }
        }

        function searchBaidu() {
            var text = $("#Title").val();
            if (text.length > 0) {
                var data = { keyword: text };
                $.ajax({
                    url: '@Url.Action("SearchFromBaidu")',
                    type: "POST",
                    data: data,
                    success: function (result) {
                        $("#result").show();
                        searchResult = result;
                        for (var i = 0; i < searchResult.length; i++) {
                            var html = "<tr>";
                            html += "<td>" + searchResult[i].Title + "</td>";
                            html += "<td>" + searchResult[i].PubYear + "</td>";
                            html += "<td>" + searchResult[i].AreaId + "</td>";
                            html += "<td>" + searchResult[i].Directors + "</td>";
                            html += "<td>" + searchResult[i].Actors + "</td>";
                            html += "<td><a href='javascript:selectItem(" + i + ")'>选择</a></td>";
                            html += "</tr>";
                            $("#searchResult").append(html);
                        }
                    },
                    error: function () {
                        alert("搜索发生错误。");
                    }
                });
            }
        }
    </script>
}
<h2 class="pageTitle">@ViewBag.Title</h2>
<div class="ten-form">
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    @Html.HiddenFor(model => model.Id)
<table class="table-form">
    <tr>
        <td class="label">@Html.LabelFor(model => model.Title)</td>
        <td>
            @Html.TextBoxFor(model => model.Title, new { @class = "long" })
            <a href="javascript:searchBaidu()" class="lbtn" plain="true">从百度查找</a>
            @Html.ValidationMessageFor(model => model.Title)
        </td>
    </tr>
    <tr>
        <td class="label">@Html.LabelFor(model => model.TypeId)</td>
        <td>
            @Html.DropDownList("TypeId", "请选择")
            @Html.ValidationMessageFor(model => model.TypeId)
        </td>
    </tr>
    <tr>
        <td class="label">@Html.LabelFor(model => model.AreaId)</td>
        <td>
        @Html.DropDownList("AreaId", "请选择")
        @Html.ValidationMessageFor(model => model.AreaId)
        </td>
    </tr>
    <tr>
        <td class="label">@Html.LabelFor(model => model.Rating)</td>
        <td>
        @Html.TextBoxFor(model => model.Rating, new { @class = "short" })
        @Html.ValidationMessageFor(model => model.Rating)
        </td>
    </tr>
    <tr>
        <td class="label">@Html.LabelFor(model => model.Actors)</td>
        <td>
        @Html.EditorFor(model => model.Actors)
        @Html.ValidationMessageFor(model => model.Actors)
        </td>
    </tr>
    <tr>
        <td class="label">@Html.LabelFor(model => model.Directors)</td>
        <td>
            @Html.EditorFor(model => model.Directors)
            @Html.ValidationMessageFor(model => model.Directors)
        </td>
    </tr>
    <tr>
        <td class="label">@Html.LabelFor(model => model.PubYear)</td>
        <td>
            @Html.EditorFor(model => model.PubYear)
            @Html.ValidationMessageFor(model => model.PubYear)
        </td>
    </tr>
    <tr>
        <td class="label">@Html.LabelFor(model => model.IsEnd)</td>
        <td>
            @Html.EditorFor(model => model.IsEnd)
            @Html.ValidationMessageFor(model => model.IsEnd)
        </td>
    </tr>
    <tr>
        <td class="label">@Html.LabelFor(model => model.Priority)</td>
        <td>
            @Html.EditorFor(model => model.Priority)
            @Html.ValidationMessageFor(model => model.Priority)
        </td>
    </tr>
    <tr>
        <td class="label">@Html.LabelFor(model => model.BaiduId)</td>
        <td>
        @Html.EditorFor(model => model.BaiduId)
        @Html.ValidationMessageFor(model => model.BaiduId)
        </td>
    </tr>
    <tr>
        <td class="label">@Html.LabelFor(model => model.Status)</td>
        <td>
            @Html.DropDownList("Status", "请选择")
            @Html.ValidationMessageFor(model => model.Status)
        </td>
    </tr>
    <tr>
        <td class="label">@Html.LabelFor(model => model.Description)</td>
        <td>
            @Html.EditorFor(model => model.Description)
            @Html.ValidationMessageFor(model => model.Description)
        </td>
    </tr>
    <tr>
        <td class="label"></td>
        <td>
        <input type="submit" value="保存" />
        @Html.ActionLink("返回", "Index", null, new { @class="lbtn"} )
        </td>
    </tr>
</table>
}
</div>
<div class="unit" style="display: none" id="result">
    <table width="100%" class="list">
        <thead>
            <tr>
                <th width="200">
                    视频名称
                </th>
                <th width="50">
                    年代
                </th>
                <th width="50">
                    地区
                </th>
                <th width="200">
                    导演
                </th>
                <th width="200">
                    主演
                </th>
                <th>
                </th>
            </tr>
        </thead>
        <tbody id="searchResult">
        </tbody>
    </table>
</div>
